import dt from '@dt/dt'
import Opt from '@/components/dt/info/Opt.js'
import houseOpt from '@/biz/option/house.js'
import businessCommonMgr from '@/biz/businessReport/businessCommon'
let companys = []
class SearchOpt extends Opt {

  constructor() {
    super()
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      this.getCompany(),
      houseOpt.create({
        title: '所属案场',
        to: (info) => {
          return {
            buildingId: info.housesId,
          }
        }
      })
    ]
  }
  getCompany() {
    let opt = {
      title: '组织筛选',
      key: 'companyIds',
      placeholder: '全部',
      tree: {
        options: [],
        saveAll: true
      },
      change: (v) => {
        // let companyIds = [],
        //   officeIds = []
        // v && v.editValue.forEach(item => {
        //   if (item.level == 2) {
        //     companyIds.push(item.id)
        //   } else if (item.level == 3) {
        //     officeIds.push(item.id)
        //   }
        // });
        // v.info.companyIds = companyIds
        // v.info.officeIds = officeIds
      }
    }
    let params = {
      isTwoLevel: true,
    }
    businessCommonMgr
      .getOrgThreeTree(params)
      .then((res) => {
        companys = res
        opt.tree.options = companys
      })
    return opt
  }
}

export default SearchOpt